﻿CKEDITOR.config.customConfig = '/ckeditor/config.js';

var basicToolbar = [
    { name: 'document', groups: ['mode'] },
    { name: 'basicstyles', groups: ['basicstyles', 'cleanup'] },
    { name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi'] },
    { name: 'links' },
    { name: 'styles' },
    { name: 'insert', groups: ['glyphicons'] }
];

if (document.simpleImageBrowserURL === '') {
    CKEDITOR.config.removeButtons = 'Simple Image Browser';
} else {
    CKEDITOR.config.simpleImageBrowserURL = document.simpleImageBrowserURL;
    CKEDITOR.config.simpleImageBrowserUploadActionURL = document.simpleImageBrowserUploadActionURL;
}

var textareas = ['PromotionDetails', 'Policies', 'SmallArticle'];
textareas.forEach(function (e) {
    CKEDITOR.replace(e, {
        toolbarGroups: basicToolbar
    });
});

CKEDITOR.replace('Article', {
    height: 600,
    autoGrow_minHeight: 600
});

$(function () {
    $('.select2').select2({
        placeholder: {
            id: '0',
            text: ''
        },
        allowClear: true
    });

    $('input[type=file]').bootstrapFileInput();
    $("input[type=file]").change(function () {
        readURL(this);
    });
});

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function (e) {
            $('#previewImg').remove();
            $('<img id="previewImg" src="' + e.target.result + '" style="display:block" />').insertAfter('.file-input-name');
        }
        reader.readAsDataURL(input.files[0]);
    }
}